<?php

namespace app\common\model\distribute;

use app\common\model\hfztcy\LibAdminBalanceRecords;
use app\common\model\hfztcy\LibBalanceRecords;
use app\common\model\hfztcy\LibMember;
use app\common\model\LibAdmin;
use app\common\model\LibUser;

/**
 * @name base.php
 * @package
 * @link http://www.chanekeji.com
 * @author rxy
 * @version
 * @copyright CHANGE INC
 * @since 2023/1/10 15:01
 */
class base
{
    protected $orderInfo;

    /**
     * @var $user LibUser
     */
    protected $user;

    /**
     * @var $member LibMember
     */
    protected $member;

    /**
     * @var $curPayUserInfo LibMember
     */
    protected $curPayUserInfo;

    /**
     * @var $admin LibAdmin
     */
    protected $admin;

    /**
     * @var $balanceRecords LibBalanceRecords
     */
    protected $balanceRecords;

    /**
     * @var $adminBalanceRecords LibAdminBalanceRecords
     */
    protected $adminBalanceRecords;

    /**
     * @var $type int
     */
    protected $type;

    protected $logPath;

    /**
     * Info: 设置订单类型
     * Date: 2023/1/10 10:58
     */
    public function setOrderType ($type)
    {
        $this->type = $type;
        return $this;
    }

    /**
     * Info: 设置订单信息
     * Date: 2023/1/10 10:58
     */
    public function setOrderInfo ($order)
    {
        if ($this->orderInfo) return $this;
        $this->orderInfo = $order;
        return $this;
    }

    /**
     * Info: 设置微信用户
     * Date: 2023/1/10 10:57
     */
    public function setBaseUserModel (LibUser $user)
    {
        if ($this->user) return $this;
        $this->user = $user;
        return $this;
    }

    /**
     * Info: 设置会员信息
     * Date: 2023/1/10 10:57
     */
    public function setMemberModel (LibMember $member)
    {
        if ($this->member) return $this;
        $this->member = $member;
        return $this;
    }

    /**
     * Info: 设置管理员信息
     * Date: 2023/1/10 12:02
     */
    public function setAdminModel (LibAdmin $admin)
    {
        if ($this->admin) return $admin;
        $this->admin = $admin;
        return $this;
    }

    /**
     * Info: 设置管理员信息
     * Date: 2023/1/10 12:02
     */
    public function setBalanceRecordsModel (LibBalanceRecords $balanceRecords)
    {
        if ($this->balanceRecords) return $this;
        $this->balanceRecords = $balanceRecords;
        return $this;
    }

    /**
     * Info: 设置管理员信息
     * Date: 2023/1/10 12:02
     */
    public function setAdminBalanceRecordsModel (LibAdminBalanceRecords $balanceRecords)
    {
        if ($this->adminBalanceRecords) return $this;
        $this->adminBalanceRecords = $balanceRecords;
        return $this;
    }

    /**
     * Info: 当前支付用户
     * Date: 2023/1/10 14:19
     */
    public function setCurPayUserInfo ($user)
    {
        if ($this->curPayUserInfo) return $this;
        $this->curPayUserInfo = $user;
        return $this;
    }

    /**
     * Info: 设置日志路径
     * Date: 2023/1/10 14:38
     */
    public function setLogPath ($path)
    {
        $this->logPath = $path;
        return $this;
    }

    /**
     * Info: 写文件
     * Date: 2023/1/10 10:02
     */
    public function write_file($text)
    {
        if (@$fp = fopen($this->logPath, 'a')) {
            flock($fp, 2);
            fwrite($fp, $text . "\r\n");
            fclose($fp);
        }
    }

    public function __get($name)
    {
        $classname = "\\app\\common\\model\\distribute\\".$name;
        $this->write_file($classname);
        if (class_exists($classname)) {
            return (new $classname());
        }
        return false;
    }
}